package io.renren.modules.app.service.impl;

import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.netty.util.internal.StringUtil;
import io.renren.modules.app.req.GoodsListReq;
import io.renren.modules.app.utils.AuthUtils;
import io.renren.modules.app.vo.GoodsListVO;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.app.dao.GoodsDao;
import io.renren.modules.app.entity.GoodsEntity;
import io.renren.modules.app.service.GoodsService;


@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, GoodsEntity> implements GoodsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper queryWrapper =  new QueryWrapper<GoodsEntity>();
        if(!StringUtils.isEmpty((String)params.get("key"))){
            queryWrapper.eq("id",params.get("key"));
        }
        IPage<GoodsEntity> page = this.page(
                new Query<GoodsEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    /**
     * 商品列表
     * @param page goodsListReq
     * @return
     */
    @Override
    public PageUtils getGoodsList(Page<GoodsListVO> page, GoodsListReq goodsListReq) {
        System.out.println(page.getCurrent());
        page.setRecords(baseMapper.getGoodsList(page,goodsListReq));
        return new PageUtils(page);
    }
}